package com.cn.ant.modules.wechat.service;

import com.cn.ant.common.persistence.Page;
import com.cn.ant.common.service.BaseService;
import com.cn.ant.modules.wechat.dao.WeiXinCustomInfoMapper;
import com.cn.ant.modules.wechat.dao.WeiXinCustomItemMapper;
import com.cn.ant.modules.wechat.entity.WeiXinCustomInfo;
import com.cn.ant.modules.wechat.entity.WeiXinCustomItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;
/**
 * 微信活动参与用户Service
 * @author AntDream
 * @version 2015-04-02
 */
@Component
@Transactional(readOnly = true)
public class WeiXinCustomInfoService extends BaseService {

	@Autowired
	private WeiXinCustomInfoMapper weiXinCustomInfoMapper;
    @Autowired
    private WeiXinCustomItemMapper customItemMapper;
	
	public WeiXinCustomInfo get(String id) {
		return weiXinCustomInfoMapper.get(id);
	}
	
	public Page<WeiXinCustomInfo> find(Page<WeiXinCustomInfo> page, Map<String,Object> param) {
        param.put("startIdx", page.getFirstResult());
        param.put("pageSize", page.getPageSize());
        page.setList(weiXinCustomInfoMapper.query(param));
        page.setCount(weiXinCustomInfoMapper.queryCount(param));
        return page;
	}

    public List<WeiXinCustomItem> queryByCustomId(String customId) {
        return customItemMapper.queryByCustomId(customId);
    }

    public List<WeiXinCustomItem> queryByOpenId(String customId,String openId) {
        return customItemMapper.queryByOpenId(customId, openId);
    }

    public int queryPrizeCustom(){
        return weiXinCustomInfoMapper.queryPrizeCustom();
    }

    public WeiXinCustomInfo getByOpenId(String openId) {
        return weiXinCustomInfoMapper.getByOpenId(openId);
    }

    @Transactional(readOnly = false)
	public void save(WeiXinCustomInfo weiXinCustomInfo) {
		weiXinCustomInfoMapper.insert(weiXinCustomInfo);
	}

    @Transactional(readOnly = false)
    public void saveItem(WeiXinCustomItem item) {
        customItemMapper.insert(item);
    }

	@Transactional(readOnly = false)
	public void update(WeiXinCustomInfo weiXinCustomInfo) {
		weiXinCustomInfoMapper.update(weiXinCustomInfo);
	}
	
	@Transactional(readOnly = false)
	public void delete(String id) {
		weiXinCustomInfoMapper.delete(id);
	}
	
}
